﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.Core
{
    public class MessageHub:Hub
    {
        private readonly ILoginInfo _loginInfo;
        public MessageHub(ILoginInfo loginInfo)
        {
            _loginInfo = loginInfo;
        }
        public override async Task OnConnectedAsync()
        {
            //一个用户一个分组
            await Groups.AddToGroupAsync(Context.ConnectionId, _loginInfo.UserId);
        }
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await Groups.RemoveFromGroupAsync(Context.ConnectionId, _loginInfo.UserId);
            await base.OnDisconnectedAsync(exception);
        }
    }
}
